<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>验证回文串 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .keyword { color: #c678dd; }
        .function { color: #61afef; }
        .string { color: #98c379; }
        .number { color: #d19a66; }
        .operator { color: #56b6c2; }
        .comment { color: #5c6370; }
        .builtin { color: #e06c75; }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
        .step-indicator {
            position: relative;
            padding-left: 40px;
        }
        .step-indicator::before {
            content: attr(data-step);
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 28px;
            height: 28px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            font-size: 14px;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">验证回文串</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">掌握双指针技巧，优雅解决字符串问题</p>
            <div class="flex justify-center gap-6 text-sm">
                <span class="flex items-center gap-2">
                    <i class="fas fa-clock"></i>
                    时间复杂度 O(n)
                </span>
                <span class="flex items-center gap-2">
                    <i class="fas fa-memory"></i>
                    空间复杂度 O(1)
                </span>
                <span class="flex items-center gap-2">
                    <i class="fas fa-tag"></i>
                    双指针算法
                </span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description -->
        <section class="mb-12 animate-fadeInUp" style="animation-delay: 0.1s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-center gap-3 mb-6">
                    <div class="w-12 h-12 bg-purple-100 rounded-xl flex items-center justify-center">
                        <i class="fas fa-file-alt text-purple-600 text-xl"></i>
                    </div>
                    <h2 class="text-2xl font-bold">题目描述</h2>
                </div>
                <p class="text-gray-700 text-lg leading-relaxed">
                    给定一个字符串，验证它是否是回文串，只考虑字母和数字字符，忽略字母的大小写。
                </p>
                <div class="mt-6 p-4 bg-purple-50 rounded-lg">
                    <p class="text-purple-800">
                        <i class="fas fa-lightbulb mr-2"></i>
                        <strong>示例：</strong>"A man, a plan, a canal: Panama" → true
                    </p>
                </div>
            </div>
        </section>

        <!-- Algorithm Visualization -->
        <section class="mb-12 animate-fadeInUp" style="animation-delay: 0.2s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-center gap-3 mb-6">
                    <div class="w-12 h-12 bg-blue-100 rounded-xl flex items-center justify-center">
                        <i class="fas fa-project-diagram text-blue-600 text-xl"></i>
                    </div>
                    <h2 class="text-2xl font-bold">算法可视化</h2>
                </div>
                <div class="mermaid">
                    graph LR
                        A[开始] --> B[初始化左右指针]
                        B --> C{左指针 < 右指针?}
                        C -->|是| D[跳过非字母数字]
                        D --> E{字符相等?}
                        E -->|是| F[移动指针]
                        E -->|否| G[返回 False]
                        F --> C
                        C -->|否| H[返回 True]
                        style A fill:#667eea,stroke:#fff,color:#fff
                        style G fill:#ff5f56,stroke:#fff,color:#fff
                        style H fill:#27c93f,stroke:#fff,color:#fff
                </div>
            </div>
        </section>

        <!-- Solution Steps -->
        <section class="mb-12 animate-fadeInUp" style="animation-delay: 0.3s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-center gap-3 mb-6">
                    <div class="w-12 h-12 bg-green-100 rounded-xl flex items-center justify-center">
                        <i class="fas fa-route text-green-600 text-xl"></i>
                    </div>
                    <h2 class="text-2xl font-bold">解题思路</h2>
                </div>
                <div class="space-y-4">
                    <div class="step-indicator" data-step="1">
                        <h3 class="font-semibold text-lg mb-2">初始化双指针</h3>
                        <p class="text-gray-700">设置 left 指向字符串开头，right 指向字符串末尾</p>
                    </div>
                    <div class="step-indicator" data-step="2">
                        <h3 class="font-semibold text-lg mb-2">跳过非字母数字字符</h3>
                        <p class="text-gray-700">使用 isalnum() 方法判断字符是否为字母或数字</p>
                    </div>
                    <div class="step-indicator" data-step="3">
                        <h3 class="font-semibold text-lg mb-2">比较字符</h3>
                        <p class="text-gray-700">将字符转换为小写后进行比较，确保忽略大小写</p>
                    </div>
                    <div class="step-indicator" data-step="4">
                        <h3 class="font-semibold text-lg mb-2">移动指针</h3>
                        <p class="text-gray-700">如果字符相等，继续向中间移动；否则返回 False</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Implementation -->
        <section class="mb-12 animate-fadeInUp" style="animation-delay: 0.4s;">
            <div class="bg-white rounded-2xl shadow-lg overflow-hidden card-hover">
                <div class="p-8 pb-0">
                    <div class="flex items-center gap-3 mb-6">
                        <div class="w-12 h-12 bg-orange-100 rounded-xl flex items-center justify-center">
                            <i class="fas fa-code text-orange-600 text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold">代码实现</h2>
                    </div>
                </div>
                <div class="code-block mx-8 mb-8">
                    <div class="code-header">
                        <div class="code-dots">
                            <div class="dot dot-red"></div>
                            <div class="dot dot-yellow"></div>
                            <div class="dot dot-green"></div>
                        </div>
                        <span class="text-gray-400 text-sm">Python</span>
                    </div>
                    <pre><code><span class="keyword">def</span> <span class="function">isPalindrome</span>(s):
    <span class="comment"># 初始化左右指针</span>
    left, right = <span class="number">0</span>, <span class="builtin">len</span>(s) <span class="operator">-</span> <span class="number">1</span>
    
    <span class="keyword">while</span> left <span class="operator">&lt;</span> right:
        <span class="comment"># 跳过左边的非字母数字字符</span>
        <span class="keyword">while</span> left <span class="operator">&lt;</span> right <span class="keyword">and</span> <span class="keyword">not</span> s[left].isalnum():
            left <span class="operator">+=</span> <span class="number">1</span>
        
        <span class="comment"># 跳过右边的非字母数字字符</span>
        <span class="keyword">while</span> left <span class="operator">&lt;</span> right <span class="keyword">and</span> <span class="keyword">not</span> s[right].isalnum():
            right <span class="operator">-=</span> <span class="number">1</span>
        
        <span class="comment"># 比较字符（忽略大小写）</span>
        <span class="keyword">if</span> s[left].lower() <span class="operator">!=</span> s[right].lower():
            <span class="keyword">return</span> <span class="builtin">False</span>
        
        <span class="comment"># 移动指针</span>
        left <span class="operator">+=</span> <span class="number">1</span>
        right <span class="operator">-=</span> <span class="number">1</span>
    
    <span class="keyword">return</span> <span class="builtin">True</span></code></pre>
                </div>
            </div>
        </section>

        <!-- Complexity Analysis -->
        <section class="mb-12 animate-fadeInUp" style="animation-delay: 0.5s;">
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white rounded-2xl shadow-lg p-6 card-hover">
                    <div class="flex items-center gap-3 mb-4">
                        <div class="w-10 h-10 bg-indigo-100 rounded-lg flex items-center justify-center">
                            <i class="fas fa-clock text-indigo-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">时间复杂度分析</h3>
                    </div>
                    <p class="text-gray-700 mb-3">O(n) - 其中 n 是字符串的长度</p>
                    <p class="text-sm text-gray-600">每个字符最多被访问一次，双指针从两端向中间移动</p>
                </div>
                <div class="bg-white rounded-2xl shadow-lg p-6 card-hover">
                    <div class="flex items-center gap-3 mb-4">
                        <div class="w-10 h-10 bg-pink-100 rounded-lg flex items-center justify-center">
                            <i class="fas fa-memory text-pink-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">空间复杂度分析</h3>
                    </div>
                    <p class="text-gray-700 